/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sdd.entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author tpgalan
 */
@Entity
public class Category implements Serializable {
    private static final long serialVersionUID = 1L;
    
    private Long id;
    private String name;
    private Category father;
    private List<Category> son;
    private List<Product> products;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Category)) {
            return false;
        }
        Category other = (Category) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.sdd.entities.Category[ id=" + id + " ]";
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the father
     */
    @ManyToOne
    public Category getFather() {
        return father;
    }

    /**
     * @param father the father to set
     */
    public void setFather(Category father) {
        this.father = father;
    }

    /**
     * @return the son
     */
    @OneToMany(mappedBy="father")
    public List<Category> getSon() {
        return son;
    }

    /**
     * @param son the son to set
     */
    public void setSon(List<Category> son) {
        this.son = son;
    }

    /**
     * @return the products
     */
    
    @ManyToMany(mappedBy = "categories")
    public List<Product> getProducts() {
        return products;
    }

    /**
     * @param products the products to set
     */
    public void setProducts(List<Product> products) {
        this.products = products;
    }
    
}
